﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="List.aspx.cs" Inherits="Lavanderia_List" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" media="screen,projection,print" href="<%= this.ResolveUrl("~") %>css/styles_setup.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection,print" href="<%= this.ResolveUrl("~") %>css/styles_text.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection,print" href="<%= this.ResolveUrl("~") %>css/jquery_notification.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection,print" href="<%= this.ResolveUrl("~") %>css/jquery-ui-1.9.0.custom.min.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection,print" href="<%= this.ResolveUrl("~") %>css/lightbox.css" />
    <script type="text/javascript" src="<%= this.ResolveUrl("~") %>scripts/jquery-1.8.2.min.js" ></script>
    <script type="text/javascript" src="<%= this.ResolveUrl("~") %>scripts/jquery_notification_v.1.js" ></script>
    <script type="text/javascript" src="<%= this.ResolveUrl("~") %>scripts/jquery-ui-1.9.0.custom.min.js" ></script>
    <script type="text/javascript" src="<%= this.ResolveUrl("~") %>scripts/lightbox.js" ></script>
    <script type="text/javascript" src="<%= this.ResolveUrl("~") %>scripts/jquery.ui.datepicker-es.js" ></script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="divMainContent" class="main-content">
        <asp:ScriptManager runat="server"></asp:ScriptManager>
        <asp:UpdatePanel runat="server" ID="updGrid" >
            <ContentTemplate>
                <asp:gridview ID="grid" runat="server" AutoGenerateColumns="False" OnRowCommand="grid_RowCommand" 
                    OnRowDataBound="grid_RowDataBound" CssClass="detail-table" OnRowCreated="grid_RowCreated" ShowFooter="true" >
                <Columns>  
                   <asp:TemplateField HeaderText="Proceso" HeaderStyle-CssClass="top">
                        <ItemTemplate>   
                            <asp:HiddenField runat="server" ID="hdnId" /> 
                            <asp:DropDownList runat="server" ID="drdProcess" CssClass="detail-input"></asp:DropDownList>     
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Cantidad" HeaderStyle-CssClass="top" HeaderStyle-Width="100px">
                        <ItemTemplate>    
                            <asp:TextBox ID="txtQuantity" runat="server" CssClass="detail-input digits-only quantity"></asp:TextBox>     
                        </ItemTemplate>
                    </asp:TemplateField>
                     <asp:TemplateField HeaderText="P. Unitario" HeaderStyle-CssClass="top" HeaderStyle-Width="100px">
                        <ItemTemplate>    
                            <asp:TextBox ID="txtPrice" runat="server" CssClass="detail-input digits-only price"></asp:TextBox> 
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Total" HeaderStyle-CssClass="top" HeaderStyle-Width="100px">
                        <ItemTemplate>    
                            <asp:TextBox ID="txtTotal" runat="server" ReadOnly="true" CssClass="detail-input total"></asp:TextBox> 
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:gridview>
                <asp:ImageButton runat="server" ID="imgAdd" ImageUrl="~/img/plus-icon.png" CssClass="add-rows" ToolTip="Agregar Detalles" OnClick="imgAdd_Click"/>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
    <script type="text/javascript">

        $(document).ready(function () {
            checkInputs();
            calculatePerRow();
            calculateTotalPerRow();
            calculateTotal();
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
        })
        function checkInputs()
        {
            $(".digits-only").live("keyup paste", function () {
                setTimeout(jQuery.proxy(function () {
                    $(this).val($(this).val().replace(/[^\d\,]/g, ''));
                }, $(this)), 0);

            });

        }
        function calculatePerRow() {
            $(".digits-only").live("blur", function () {
                var td = $(this).parent().parent();
                var qyt = td.find(".quantity");
                var price = td.find(".price");
                var total = td.find(".total");
                q = 0
                if (qyt.val() !="")
                    q = parseFloat(qyt.val().replace(/\,/g, "."))
                p = 0;
                if (price.val() != "")
                    p = parseFloat(price.val().replace(/\,/g, "."))
                t = (p * q)
                t = Math.round(t * 100) / 100;
                if (t > 0)
                    total.val(t.toString().replace(/\./g, ","))
                calculateTotal()
            });

        }
        function calculateTotalPerRow() {
            $(".digits-only").each(function () {
                var td = $(this).parent().parent();
                var qyt = td.find(".quantity");
                var price = td.find(".price");
                var total = td.find(".total");
                q = 0
                if (qyt.val() != "")
                    q = parseFloat(qyt.val().replace(/\,/g, "."))
                p = 0;
                if (price.val() != "")
                    p = parseFloat(price.val().replace(/\,/g, "."))
                t = (p * q)
                t = Math.round(t * 100) / 100;
                if (t > 0)
                    total.val(t.toString().replace(/\./g, ","))
            });

        }
        function calculateTotal() {
            var gT = 0
            $(".total").each(function () {
                q = 0
                if ($(this).val() != "")
                    q = parseFloat($(this).val().replace(/\,/g, "."))
                gT += q;
                gT = Math.round(gT * 100) / 100;
                if (gT > 0)
                    $(".footer-subtotal").val(gT.toString().replace(/\./g, ","))
            });

        }
        function beginRequestHandler() {
            $(".dialog").dialog({
                title: "Cargando...",
                modal: true,
                width: 50,
                height: 100,
                closeOnEscape: false,
                resizable: false,
                open: function () {
                    $(".ui-dialog-titlebar-close", $(this).parent()).hide(); //hides the little 'x' button
                    $(".ui-dialog-titlebar").hide();
                }
            });
        }
        function endRequestHandler() {
            $(".dialog").dialog('close');
            calculateTotalPerRow();
            calculateTotal();
        }
    </script>
    <div class="dialog" style="display:none;text-align:center"><br /><br />Cargando...</div>
</body>
</html>
